// pages/gallery/gallery.ts
interface GalleryData {
  avatar: string,
  imgUrl: string,
  like: number,
  star: number,
  title: string,
  username: string
}

interface Banner {
  title: string,
  firstBrief: string,
  secondBrief: string,
  startTime: string,
  endTime: string,
  imgUrl: string,
}

Page({
  /**
   * 页面的初始数据
   */
  data: {
    banner: {} as Banner,
    gallery: [] as GalleryData[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  goToMore() {
    wx.navigateTo({
      url: '/package-gallery/pages/past/past'
    })
  },
  goToDetail() {
    wx.navigateTo({
      url: '/package-gallery/pages/gallery-detail/gallery-detail'
    })
  },
  onLoad() {
    wx.request({
      url: 'https://mock.presstime.cn/mock/656dbe322fef936d34630d40/yi-xiao-ping/gallery',
      success: (
        res: {
          data: {
            code: number,
            data: {
              banner: Banner,
              galleryData: GalleryData[]
            },
            msg: string,
          },
        }
      ) => {
        const { data } = res
        const { data: responseData, code } = data
        console.log(responseData)
        if (code === 200) {
          const { banner, galleryData } = responseData;
          this.setData({
            banner: {
              ...banner
            },
            gallery: [
              ...galleryData,
            ]
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})